{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5f214bbf",
   "metadata": {},
   "source": [
    "----\n",
    "* 阶段:week10\n",
    "* 目标:实现web应用\n",
    "* 时间:2023-11-08"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "484f9970",
   "metadata": {},
   "source": [
    "# 本周内容：Web应用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f54b165b",
   "metadata": {},
   "source": [
    "## 先使用Flask搭建Web最小应用\n",
    "> 1.使用select创建一个html页面：index.html\n",
    "\n",
    "> 2.使用Flask中的render_template实现页面的路由跳转"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf3d6c48",
   "metadata": {},
   "outputs": [],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def hello_world():\n",
    "   return render_template('index.html')\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57f51338",
   "metadata": {},
   "source": [
    "## 提交表单的内容在python中接收"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b1ed5528",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app '__main__'\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\n",
      " * Running on http://127.0.0.1:5000\n",
      "Press CTRL+C to quit\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template,request\n",
    "import crawl_liepin\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "     return render_template('index.html')\n",
    "    \n",
    "@app.route('/user_choose',methods = ['POST','GET'])\n",
    "def user_choose():\n",
    "    print(request.form['city'])\n",
    "    print(request.form['catagory'])\n",
    "    print(request.form['workexp'])\n",
    "    user_city = request.form['city']\n",
    "    user_catagory = request.form['catagory']\n",
    "    user_workexp = request.form['workexp']\n",
    "    crawl_results = crawl_liepin.crawl(城市=user_city,关键词=user_catagory,工作经验= user_workexp)\n",
    "    crawl_results_html = crawl_results.to_html()\n",
    "    return render_template(\"user_choose.html\",\n",
    "                           crawl_results_html = crawl_results_html)\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a322c89",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec73bb80",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
